#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>


int main()
{
	fd_set			readfds,testfds;
	char			readbuf[32];

	FD_ZERO(&readfds);
	FD_SET(0, &readfds);

	int result;

	while(1)
	{
		printf("kbd runing\n");
		testfds = readfds;			//here use testfd instead of readfds
		result	= select(0+1, &testfds, NULL, NULL, NULL);

		switch(result)
		{
			case 0:
				break;
			case -1:
				perror("select");
				fprintf(stderr,"ERR:select:%m\n");
				exit(1);
			default:
				if(FD_ISSET(0, &testfds))
				{
					ioctl(0, FIONREAD, &result);
					if(result == 0)
					{
						printf( "what's the signal?\n");								/////////////////////////change
						exit(0);
					}
					
					result = read(0, readbuf, result > 32? 32:result);
					readbuf[result] = '\0';
					
					if(strncmp(readbuf, "quit", strlen("quit")) == 0)				///////////////////////////change
					{
						printf( "service stop\n\n");
						exit(0);	
					}
					else
					{
						printf("unknown command\n");									//////////////////////////change
					}
				}
				break;
		}
	
	}
	printf("!!normally will nerver get here!!\n");
	return 0;				
}
